package com.control.qct.businesssteward.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ExpandableListView;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.model.AllAccountDetailModel;
import com.control.qct.businesssteward.utils.DecimalFormatUtils;
import com.control.qct.businesssteward.view.CustomExpandableListView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/12/13 0013.
 */

public class AccountDetailAdapter extends BaseQuickAdapter<AllAccountDetailModel.CashierSaleOrderListBean,
        BaseViewHolder> {
    public AccountDetailAdapter(@Nullable List<AllAccountDetailModel.CashierSaleOrderListBean> data) {
        super(R.layout.rv_shop_account_detail_item, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, AllAccountDetailModel.CashierSaleOrderListBean item) {
        holder.setText(R.id.tv_guide_name, item.getCashier()).setText(R.id.tv_first_time, "首笔时间：" + item.getFirstTime
                ()).setText(R.id.tv_end_time, "末笔时间：" + item.getLastTime());
        int totalCount = 0;
        double totalMoney = 0;
        for (int i = 0; i < item.getTotalTypes().size(); i++) {
            if (item.getTotalTypes().get(i).getCount() > 0) {
                totalCount += item.getTotalTypes().get(i).getCount();
                totalMoney += item.getTotalTypes().get(i).getMoney();
            }
        }
        holder.setText(R.id.tv_stroke_count, totalCount + "");
        holder.setText(R.id.tv_cash_price, "￥" + DecimalFormatUtils.DecimalFormatTwo(totalMoney));
        CustomExpandableListView elvAccountDetail = holder.getView(R.id.elv_account_detail);
        elvAccountDetail.setAdapter(new AccountDetialChildAdapter(mContext, item.getTotalTypes()));
        int count = elvAccountDetail.getCount();
        for (int i = 0; i < count; i++) {
            elvAccountDetail.expandGroup(i);
        }
        elvAccountDetail.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
                return true;//默认false 返回true则不响应点击事件
            }
        });
    }
}
